package com.zw.yzk.kabu.presenter;

import android.support.v7.app.AppCompatActivity;

import com.zw.yzk.kabu.base.BaseSubscriber;
import com.zw.yzk.kabu.data.network.entity.ImInfoEntity;
import com.zw.yzk.kabu.data.network.task.ImInfoTask;
import com.zw.yzk.kabu.domain.repository.UseCase;
import com.zw.yzk.kabu.view.view.ConversationView;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/5/14.
 */

public class ImInfoPresenter implements Presenter {

    private UseCase getImInfo;
    private AppCompatActivity activity;
    private ConversationView conversationView;

    @Inject
    public ImInfoPresenter(UseCase getImInfo, AppCompatActivity activity) {
        this.getImInfo = getImInfo;
        this.activity = activity;
    }

    public void setVeiw(ConversationView view) {
        this.conversationView = view;
    }

    public void getImInfo(String userId) {
        getImInfo.execute(new ImInfoSubscriber(activity), new ImInfoTask(userId));
    }

    @Override
    public void resume() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void destroy() {
        getImInfo.unSubscribe();
    }

    private class ImInfoSubscriber extends BaseSubscriber<ImInfoEntity> {

        public ImInfoSubscriber(AppCompatActivity appCompatActivity) {
            super(appCompatActivity);
        }

        @Override
        public void onNext(ImInfoEntity entity) {
            super.onNext(entity);
            conversationView.getImInfoSuccess(entity);
        }

        @Override
        public String addErrorMessage() {
            return "";
        }
    }
}
